<template>
  <div class="apiTab">
    <div class="tab">
      <div @click="tabChange(item)" :class="['tabItem',{active:item.category==select}]" v-for="(item,index) in tabList" :key="index">{{item.category}}</div>
    </div>
    <div class="tabBox">
      <el-checkbox-group v-model="list">
        <el-checkbox :disabled="apiInfo.auditStatus==1 " :label="item.id" v-for="(item,index) in checkList" :key="item.id"><span @click="goDetial(item)">{{item.name}}</span></el-checkbox>
      </el-checkbox-group>
      <div class="btnBox">
        <div class="btn" @click="submit">提交</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "apiTab",
  methods:{
    goDetial(item){
      let {href} = this.$router.resolve({name:'apiDetial',query:{id:item.id}})
      window.open(href,'_blank')
    },
    tabChange(item){
      this.select=item.category
      this.checkList = this.checkListMap[this.select]
    },
    submit(){
      let params = {
        id:this.apiInfo.id,
        remark:'',
        apiApplyInfoPO:this.list.map(x=>{return {id:x,status:1}})
      }
      this.$api.applyApiService(params).then(res=>{
        this.$notify({
          title: '成功',
          message: '提交成功',
          type: 'success'
        });
      })
    },
    setData(data){
      this.apiInfo = data
      this.tabList = data.apiApplicationCategory.map(x=>{
        return {
          category:x.category
        }
      })
      this.select = this.tabList[0].category
      data.apiApplicationCategory.forEach(x=>{
        this.checkList[x.category] = x.apiApplicationMethodPOS
        x.apiApplicationMethodPOS.forEach(y=>{
          if(y.status ==1){
            this.list = [...this.list,y.id]
          }
        })
      })

      this.tabList = []
      this.list = []
      this.checkList = []
      setTimeout(()=>{
        this.tabList = data.apiApplicationCategory.map(x=>{
          return {
            category:x.category
          }
        })
        this.select = this.tabList[0].category
        data.apiApplicationCategory.forEach(x=>{
          this.checkListMap[x.category] = x.apiApplicationMethodPOS
          x.apiApplicationMethodPOS.forEach(y=>{
            if(y.status ==1){
              this.list = [...this.list,y.id]
            }
          })
        })
        this.checkList = this.checkListMap[this.select]
      },300)
    },
  },
  data(){
    return {
      apiInfo:{},
      tabList:[],
      checkListMap: {},
      checkList: [],
      select:'',
      list:[],
    }
  },
}
</script>

<style scoped lang="scss">
.tab{
  display: flex;
  .tabItem{
    width: 80px;
    height: 32px;
    background: #C0D5FF;
    border-radius: 4px 4px 0px 0px;
    margin-right: 9px;
    line-height: 32px;
    text-align: center;
    color: #666666;
  }
  .active{
    font-weight: 600;
    color: #0F47B8;
  }
}
.tabBox{
  width: calc(100% - 40px);
  min-height: 450px;
  background-color: white;
  padding: 20px 20px ;
}
.btnBox{
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  .btn{
    width: 66px;
    height: 26px;
    background: #0F47B8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: white;
    cursor: pointer;
  }
}
</style>






